﻿using MediatR;
using System.CJL.API.Application.Command.StorageCommand;
using System.CJL.Infrstructre.Interface;

namespace System.CJL.API.Application.CommandHanlder.StorageCommandHandler
{
    /// <summary>
    /// 修改
    /// </summary>
    public class StorageUpdateCommandHandler :IRequestHandler<StorageUpdateCommand,int>
    {
        IStorageRepository _repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="repository"></param>
        public StorageUpdateCommandHandler(IStorageRepository repository)
        {
            _repository=repository;
        }

        public async Task<int> Handle(StorageUpdateCommand request, CancellationToken cancellationToken)
        {
            return await _repository.UpdateAsync(new Domain.Storage
            {
                StorageId=request.StorageId,
                StorageName = request.StorageName,
                StorageNumbering = request.StorageNumbering,
                StorageDate = request.StorageDate,
                StorageRemark = request.StorageRemark,
                DetailsName = request.DetailsName,
                DetailsNumbering = request.DetailsNumbering,
                DetailsSpec = request.DetailsSpec,
                DetailsUnit = request.DetailsUnit,
                DetailsNumber = request.DetailsNumber,
                DetailsNum = request.DetailsNum,
                WarehouseName = request.WarehouseName,
                ReservoirName = request.ReservoirName,
                LocationName = request.LocationName,
                DetailsDate = request.DetailsDate,
                WarehouseHead = request.WarehouseHead,
                AddName = request.AddName,
                AddTime = request.AddTime,
                UpdateName=request.UpdateName,
                UpdateTime = DateTime.Now.ToUniversalTime(),
            });
        }
    }
}
